# -*- python -*-
# vi: set ft=python :

load("//:ros_cc.bzl", "ros_cc_binary", "ros_cc_test")
load("//:ros_py.bzl", "ros_py_binary", "ros_py_test")

py_library(
    name = "module_py",
    srcs = ["__init__.py"],
)

py_library(
    name = "rmw_isolation_py",
    srcs = ["rmw_isolation.py"],
    deps = [
        ":module_py",
        "//:rclpy_py",
    ],
    # TODO(eric.cousineau, sloretz): This import path may shadow something in
    # the future.
    imports = ["."],
    visibility = ["//visibility:public"],
)

ros_py_binary(
    name = "generate_isolated_rmw_env",
    srcs = ["generate_isolated_rmw_env.py"],
    main = "generate_isolated_rmw_env.py",
    deps = [":rmw_isolation_py"],
    legacy_create_init = False,
)

cc_library(
    name = "rmw_isolation_cc",
    srcs = ["rmw_isolation.cc"],
    hdrs = ["rmw_isolation.h"],
    include_prefix = "rmw_isolation",
    data = [":generate_isolated_rmw_env"],
    local_defines = [
        "RMW_ISOLATION_ROOTPATH={}/{}".format(
            repository_name().strip("@") or ".",
            package_name(),
        ),
    ],
    deps = [
        "@bazel_tools//tools/cpp/runfiles",
        "//:rclcpp_cc",
    ],
    visibility = ["//visibility:public"],
)

ros_py_test(
    name = "rmw_isolation_py_test",
    srcs = ["test/rmw_isolation_test.py"],
    main = "test/rmw_isolation_test.py",
    args = ["--number_of_isolated_pairs", "5"],
    data = [
        "@ros2",
    ],
    deps = [
        "@bazel_tools//tools/python/runfiles",
        "@ros2//resources/rmw_isolation:rmw_isolation_py",
        "//:std_msgs_py",
    ],
)

ros_cc_test(
    name = "rmw_isolation_cc_test",
    size = "small",
    srcs = ["test/rmw_isolation_test.cc"],
    args = ["--number_of_isolated_pairs", "5"],
    rmw_implementation = "rmw_cyclonedds_cpp",
    deps = [
        "@ros2//:rclcpp_cc",
        "@ros2//:std_msgs_cc",
        "@ros2//resources/rmw_isolation:rmw_isolation_cc",
        "@com_github_gflags_gflags//:gflags",
        "@fmt",
    ],
)
